//
// Top navigation bar
// --------------------------------------------------

@mainmenu-mode-tile-height: 78px;
@mainmenu-mode-inline-height: 60px;
@mainmenu-mode-collapse-height: 45px;

@mainmenu-icon-dimension: 30px;
@mainmenu-tile-dimension: 65px;
@mainmenu-tile-label-height: 20px;
@mainmenu-tile-label-width: 100px;

body.mainmenu-open {
    overflow: hidden;
    position: fixed;
}

.mainmenu-item-link() {
    display: inline-block;
    font-size: @font-size-base;
    color: inherit;

    &:hover {
        background-color: transparent;
    }

    &:active, &:focus {
        text-decoration: none;
        color: @color-mainmenu-inactive;
    }

    i {
        line-height: 1;
        font-size: 30px;
        vertical-align: middle;
    }
}

.mainmenu-item-link-active() {
    // background: @color-mainmenu-active-bg;
    // .border-radius(3px);
    // .box-shadow(inset 0 -2px 0 rgba(0,0,0,.25));
}

.mainmenu-set-height(@height) {
    height: @height;

    ul.mainmenu-toolbar {
        li.mainmenu-preview {
            a {
                height: @height;
                line-height: @height;
            }
        }

        li.mainmenu-account {
            > a {
                height: @height;
                line-height: @height;
            }
        }
    }

    ul li .mainmenu-accountmenu {
        top: @height + 10;
    }
}

.mainmenu-tooltip {
    .tooltip-inner {
        font-size: @font-size-base - 1;
        padding: 6px 16px;
    }
}

ul.mainmenu-nav {
    font-size: @font-size-base;

    li {
        /* Fix for SVG icons not rendering on initial page load until repaint (hover, move, etc) */
        .svg-icon {
            -webkit-backface-visibility: hidden;
            backface-visibility: hidden;
        }

        span.counter {
            display: block;
            position: absolute;
            top: .143em;
            right: 0;
            padding: .143em .429em .214em .286em;
            background-color: @color-sidebarnav-counter-bg;
            color: @color-sidebarnav-counter-text;
            font-size: .786em;
            line-height: 100%;
            .border-radius(3px);
            .opacity(1);
            .scale(1);
            .transition(all 0.3s);

            &.empty {
                .opacity(0);
                .scale(0);
            }
        }
    }
}

nav#layout-mainmenu {
    background-color: @color-mainmenu;
    padding: 0 0 0 20px;
    line-height: 0;
    white-space: nowrap;
    display: flex;

    a {
        text-decoration: none;
        &:focus {
            background: transparent;
        }
    }

    ul {
        margin: 0;
        padding: 0;
        list-style: none;
        float: left;
        white-space: nowrap;
        overflow: hidden;

        li {
            color: @color-mainmenu-inactive;
            display: inline-block;
            vertical-align: top;
            position: relative;
            margin-right: 30px;

            a {
                .mainmenu-item-link();
                padding: 14px 0 10px;

                img.svg-icon {
                    height: 30px;
                    width: 30px;
                    margin-right: 10px;
                    position: relative;
                    top: 0;
                }
            }
        }

        &.nav {
            display: inline-block;
        }
    }

    .toolbar-item {
        flex: 1 1 auto;
        display: block;
        padding-right: 0;
        overflow: hidden;

        &-account {
            flex: 0 0 auto;
        }

        &:before, &:after {
            margin-top: 0;
        }

        &:before {
            left: -12px;
        }

        &:after {
            right: -12px;
        }

        &.scroll-active-before:before {
            color: @color-mainmenu-active;
        }

        &.scroll-active-after:after {
            color: @color-mainmenu-active;
        }
    }

    //
    // Toolbar
    //

    ul.mainmenu-toolbar {
        li.mainmenu-preview {
            margin: 0 0 0 21px;

            i {
                font-size: 20px;
            }

            a {
                position: relative;
                padding: 0 10px;
                top: -1px;
            }
        }

        li.mainmenu-account {
            margin-right: 0;

            > a {
                padding: 0 15px 0 10px;
                font-size: @font-size-base - 1;
                position: relative;
            }

            &.highlight > a {
                z-index: @zindex-popover;
            }

            img.account-avatar {
                width: 45px;
                height: 45px;
            }

            .account-name {
                //font-weight: bold;
                margin-right: 15px;
            }

            ul {
                line-height: 23px;
            }
        }
    }

    //
    // Fading animation (disabled)
    //

    &:hover {
        ul.mainmenu-nav li {
            //.transition(opacity .15s ease);
            //.opacity(1);
        }
    }

    ul.mainmenu-nav li {
        //.opacity(.65);
        //.transition(opacity 5s ease);
        //.transition-delay(5s);

        &.active {
            //.opacity(1);
        }
    }
}

//
// SVG support
//

html.svg {
    nav#layout-mainmenu,
    .mainmenu-collapsed {
        img.svg-icon {
            display: inline-block;
        }
    }
}

//
// User account menu
//

nav#layout-mainmenu ul li .mainmenu-accountmenu {
    position: fixed;
    top: 0; // See mode for this value
    right: @padding-standard;
    background: @color-accountmenu-bg;
    z-index: @zindex-popover;
    display: none;
    .box-shadow(@overlay-box-shadow);
    border-radius: @border-radius-base;

    &.active {
        display: block;
    }

    &:after {
        .triangle(up, 17px, 7px, @color-accountmenu-bg);
        right: 9px;
        top: -7px;
        position: absolute;
    }

    ul {
        float: none;
        display: block;
        overflow: visible;
    }

    li {
        padding: 0;
        margin: 0;
        font-weight: normal;
        text-align: left;
        display: block;

        a {
            display: block;
            padding: (@padding-standard * 0.5) (@padding-standard * 1.5);
            text-align: left;
            font-size: @font-size-base;
            color: @color-accountmenu-text;

            &:hover, &:focus {
                background: @highlight-hover-bg;
                color: @highlight-hover-text;
            }

            &:active {
                background: @highlight-active-bg;
                color: @highlight-active-text;
            }
        }

        &:first-child a {
            &:hover, &:focus, &:active {
                &:after {
                    .triangle(up, 17px, 7px, @highlight-hover-bg);
                    position: absolute;
                    right: 9px;
                    top: -7px;
                    z-index: 102;
                }
            }
            &:active {
                &:after {
                    .triangle(up, 17px, 7px, @highlight-active-bg);
                }
            }
        }
    }

    li.divider {
        height: 1px;
        width: 100%;
        background-color: @color-accountmenu-divider;
    }
}

//
// Navbar (Inline mode)
//

nav#layout-mainmenu.navbar-mode-inline,
nav#layout-mainmenu.navbar-mode-inline_no_icons {
    .mainmenu-set-height(@mainmenu-mode-inline-height);

    ul.mainmenu-nav {
        li {
            margin: 5px 0;

            a {
                padding: 10px 15px;

                .nav-icon {
                    position: relative;
                    top: -1px;
                    margin-right: 5px;
                    width: @mainmenu-icon-dimension;
                    height: @mainmenu-icon-dimension;
                    i, img { margin: 0; }
                }
                .nav-label {
                    line-height: @mainmenu-icon-dimension;
                }
            }

            &:first-child {
                margin-left: -13px;
            }

            &:last-child {
                margin-right: 0;
            }
        }

        li.active {
            .mainmenu-item-link-active();

            // &:first-child {
            //     margin-left: 0;
            // }
        }

    }
}

//
// Navbar (Inline no icons mode)
//
nav#layout-mainmenu.navbar-mode-inline_no_icons .nav-icon {
    display: none !important;
}

//
// Navbar (Tiles mode)
//

nav#layout-mainmenu.navbar-mode-tile {
    .mainmenu-set-height(@mainmenu-mode-tile-height);
    .mainmenu-navbar-tiles();
}

.mainmenu-navbar-tiles() {
    ul.mainmenu-nav {
        li a {
            position: relative;
            width: @mainmenu-tile-dimension;
            height: @mainmenu-tile-dimension;

            // Offset from bottom
            @tile-bottom-offset: 4;

            .nav-icon {
                text-align: center;
                display: block;
                position: absolute;
                top: 50%;
                left: 50%;
                margin-left: -(@mainmenu-icon-dimension / 2);
                margin-top: -((@mainmenu-tile-dimension - @mainmenu-tile-label-height) / 2) - @tile-bottom-offset;
                width: @mainmenu-icon-dimension;
                height: @mainmenu-icon-dimension;
                i, img { margin: 0; }
            }

            .nav-label {
                display: block;
                width: @mainmenu-tile-label-width;
                height: @mainmenu-tile-label-height;
                line-height: @mainmenu-tile-label-height;
                position: absolute;
                bottom: @tile-bottom-offset + 0px;
                left: 50%;
                padding: 0 5px;
                margin-left: -(@mainmenu-tile-label-width / 2);
                overflow: hidden;
                text-overflow: ellipsis;
                text-align: center;
            }
        }

        li {
            padding: 0 15px;
            margin: 7px 0 0;

            &:first-child {
                margin-left: -7px;
            }

            &:hover {
                .nav-label {
                    width: auto;
                    min-width: @mainmenu-tile-label-width;
                    text-overflow: all;
                    overflow: visible;
                    z-index: 2;
                }
            }

        }

        li.active {
            .mainmenu-item-link-active();

            a {
                // font-weight: bold;
            }

            &:first-child {
                margin-left: 0;
            }
        }
    }
}

//
// Mobile (Collapsed mode)
//

nav#layout-mainmenu {
    .menu-toggle {
        height: @mainmenu-mode-collapse-height;
        line-height: @mainmenu-mode-collapse-height;
        font-size: @font-size-base + 2;
        display: none;

        .menu-toggle-icon {
            background: #333;
            display: inline-block;
            height: @mainmenu-mode-collapse-height;
            line-height: @mainmenu-mode-collapse-height;
            width: @mainmenu-mode-collapse-height;
            text-align: center;
            opacity: .7;

            i {
                line-height: @mainmenu-mode-collapse-height;
                font-size: 20px;
                vertical-align: bottom;
            }
        }

        .menu-toggle-title {
            margin-left: 10px;
        }

        &:hover {
            .menu-toggle-icon {
                opacity: 1;
            }
        }
    }
}

body.mainmenu-open {
    nav#layout-mainmenu {
        .menu-toggle-icon {
            opacity: 1;
        }
    }
}

nav#layout-mainmenu.navbar-mode-collapse {
    .mainmenu-navbar-collapse();
}

@media (max-width: @menu-breakpoint-max) {
    nav#layout-mainmenu.navbar {
        .mainmenu-navbar-collapse();
    }
}

.mainmenu-navbar-collapse() {
    padding-left: 0;

    .mainmenu-set-height(@mainmenu-mode-collapse-height);

    ul.mainmenu-toolbar li.mainmenu-account > a {
        padding-right: 0;
    }

    ul li .mainmenu-accountmenu:after {
        right: 13px;
    }

    ul.nav { display: none; }

    .menu-toggle {
        display: inline-block;
        color: @color-mainmenu-active !important;
        // font-weight: bold;
    }
}

.mainmenu-collapsed {
    position: absolute;
    height: 100%;
    top: 0;
    left: 0;
    margin: 0;
    background: @color-mainmenu-collapsed;

    > div {
        display: block;
        height: 100%;

        .mainmenu-navbar-tiles();

        ul.mainmenu-nav li:first-child {
            margin-left: 0;
        }

        ul {
            margin: 0;
            padding: 5px 0 15px 15px;
            overflow: hidden;
        }

        ul li {
            color: @color-mainmenu-inactive;
            display: inline-block;
            vertical-align: top;
            position: relative;
            margin-right: 30px;
        }

        ul li a {
            .mainmenu-item-link();

            img.svg-icon {
                height: 30px;
                width: 30px;
                position: relative;
                top: 0;
            }
        }
    }

    .vertical-scroll-marker(@color-mainmenu-inactive);
}

body.mainmenu-open .mainmenu-collapsed ul {
    position: absolute;
    left: 0;
    top: 10px;
    bottom: 10px;
}

html.mobile {
    .mainmenu-collapsed ul {
        overflow: auto;
        -webkit-overflow-scrolling: touch;
    }
}

//
// Misc
//

nav#layout-mainmenu.navbar ul li:hover,
.mainmenu-collapsed li:hover {
    a {
        &:active, &:focus {
            color: @color-mainmenu-active !important;
        }
    }
}

.touch .mainmenu-collapsed li a:hover {
    color: @color-mainmenu-inactive;
}

nav#layout-mainmenu.navbar ul li,
.mainmenu-collapsed li {

    // Used by account menu
    &.highlight > a {
        color: @color-mainmenu-active !important;
    }

    &.active {
        color: @color-mainmenu-active !important;

        a {
            color: @color-mainmenu-active !important;
        }
    }

    &:hover {
        color: @color-mainmenu-active;
        background: transparent;
    }
}

body.drag {
    nav#layout-mainmenu.navbar ul.nav li,
    .mainmenu-collapsed ul li {
        &:hover {
            color: @color-mainmenu-inactive;
        }
    }
}
